package com.chinasoft.service.impl;

import com.chinasoft.common.Result;
import com.chinasoft.domain.User;
import com.chinasoft.mapper.UserMapper;
import com.chinasoft.service.UserService;
import com.chinasoft.vo.LoginVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;
    @Override
    public Result login(LoginVO loginVO) {
        //判断前端传过来的user对象是否为空
        if (loginVO==null){
           return Result.fail("系统异常请联系管理员!");
        }
        //用户名或者密码为空的情况
        if (loginVO.getUsername()==null || loginVO.getPassword()==null){
            return Result.fail("用户名或密码为空!");
        }
        //拿着前端传过来的username去查
        User userByUserName = userMapper.findUserByUserName(loginVO.getUsername());
        //查不到
        if(userByUserName==null){
            return  Result.fail("用户名或密码错误!");

        }
        //比较密码
        if (!loginVO.getPassword().equals(userByUserName.getPassword())){
            return  Result.fail("用户名或密码错误!");
        }
        return Result.suc(userByUserName);
    }
}
